package com.su.edu.application.service.impl;

import com.su.edu.domain.ability.UserAbility;
import com.su.edu.domain.model.UserDo;
import com.su.edu.domain.service.UserDomainService;
import com.su.edu.infra.repository.UserRepository;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * @author wangjun
 * @since 2024/6/5 14:10
 */
@Service
public class UserDomainServiceImpl implements UserDomainService {

    @Resource
    private UserAbility userAbility;

    @Resource
    private UserRepository userRepository;

    //添加注解
    @Transactional(rollbackFor = Exception.class)
    @Override
    public void saveUser(UserDo userDo) {
        userAbility.checkBeforeSave(userDo);
        userRepository.save(userDo);
        //test transaction rollback
        throw new RuntimeException();
    }

    @Override
    public void modifyUser(UserDo userDo) {
        userAbility.checkBeforeUpdate(userDo);
        userRepository.update(userDo);
    }
}
